//
//  LMNormalCell.m
//  舍品
//
//  Created by 楼 眉 on 16/3/14.
//  Copyright © 2016年 楼 眉. All rights reserved.
//

#import "LMNormalCell.h"
#import <YYWebImage.h>

@interface LMNormalCell ()

@property (nonatomic,weak)  UIImageView *showImageView;

@property (nonatomic,strong)  UILabel *nameLabel;

@property (nonatomic,weak)  UILabel *originalPriceLabel;

@property (nonatomic,weak)  UILabel *nowPriceLabel;

@property (nonatomic,weak)  UILabel *timeLabel;

@property (nonatomic,weak)  UIImageView *labelBgView;

@end
@implementation LMNormalCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        UIImageView *myImageView = [[UIImageView alloc]init];
//        self.myImageView = myImageView;
//        [self.contentView addSubview:myImageView];
        UIImageView *showImageView = [[UIImageView alloc]init];
        self.showImageView = showImageView;
        showImageView.contentMode = UIViewContentModeScaleAspectFill;
        showImageView.clipsToBounds = YES;
        [self.contentView addSubview:showImageView];
        
        UILabel *nameLabel = [[UILabel alloc]init];
        self.nameLabel = nameLabel;
        [self.contentView addSubview:nameLabel];
    
        UILabel *originalPriceLabel = [[UILabel alloc]init];
        self.originalPriceLabel = originalPriceLabel;
        [self.contentView addSubview:originalPriceLabel];
        
        UILabel *nowPriceLabel = [[UILabel alloc]init];
        self.nowPriceLabel = nowPriceLabel;
        [self.contentView addSubview:nowPriceLabel];
        
        UILabel *timeLabel = [[UILabel alloc]init];
        self.timeLabel = timeLabel;
        [self.contentView addSubview:timeLabel];
        
        UIImageView *labelBgView = [[UIImageView alloc]init];
        labelBgView.alpha = 0.4;
        labelBgView.backgroundColor = RGBCOLOR(50, 53, 53);
        self.labelBgView = labelBgView;
        [self.contentView insertSubview:labelBgView belowSubview:self.nameLabel];

    }
    return self;
}

- (void)setNormal:(AVObject *)normal
{
    _normal = normal;
    NSString *urlString = [[normal objectForKey:@"url"] firstObject];
    [self.showImageView yy_setImageWithURL:[NSURL URLWithString:urlString] placeholder:nil];
    self.showImageView.frame = CGRectMake(2, 0, SCREEN_WIDTH - 4, 200);
    
    
    NSDictionary *nameAttri = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    NSString *name = [normal objectForKey:@"commodity"];
    self.nameLabel.text = name;
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    self.nameLabel.numberOfLines = 0;
    CGSize nameLabelSize = [name boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 30, self.showImageView.height / 3) options:NSStringDrawingUsesLineFragmentOrigin attributes:nameAttri context:nil].size;
//    self.nameLabel.frame = (CGRect){{10,220 - nameLabelSize.height - 10},nameLabelSize};
    self.nameLabel.frame = (CGRect){{self.showImageView.x + 10, 200 - self.showImageView.height / 3.5 + 10},nameLabelSize};
    
    self.labelBgView.frame = CGRectMake(2, 200 - self.showImageView.height / 3.5, self.showImageView.width - 4, self.showImageView.height / 3.5);

    
}
//- (void)setUrl:(NSString *)url
//{
//    _url = url;
//    [self.myImageView yy_setImageWithURL:[NSURL URLWithString:url] placeholder:nil];
//}

#pragma mark - 重新set frame方法 调整自己位置
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 5;
    frame.size.height -= 5;
    [super setFrame:frame];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
